package com.qhs.framework.utils;

import com.github.pagehelper.Page;
import com.qhs.framework.bean.DataTableView;
import com.qhs.framework.bean.PageView;

import java.util.List;

/**
 * bean工具类
 */


public class BeanUtil {

    public static <T> DataTableView<T> toPagedResult(List<T> datas, PageView pageView) {
        DataTableView<T> result = new DataTableView<T>();
        if (datas instanceof Page) {
            Page page = (Page) datas;
            result.setDraw(pageView.getDraw());
            result.setRecordsTotal(page.getPageSize());
            result.setData(page.getResult());
            result.setRecordsFiltered(page.getTotal());
        }
        else {
            result.setDraw(1);
            result.setRecordsTotal(datas.size());
            result.setData(datas);
            result.setRecordsFiltered(datas.size());
        }

        return result;
    }

}
